﻿Imports DotNetNuke
Imports System.Web.UI
Imports System.Collections.Generic
Imports System.Reflection
Namespace SkyCorp.Modules.Directory
    Partial Class DesktopModules_Directory_AddNewUserDirectory
        Inherits Entities.Modules.PortalModuleBase
        Implements Entities.Modules.IActionable
        ''' -----------------------------------------------------------------------------
        ''' <summary>
        ''' Registers the module actions required for interfacing with the portal framework
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        ''' <history>
        ''' </history>
        ''' -----------------------------------------------------------------------------
        Public ReadOnly Property ModuleActions() As Entities.Modules.Actions.ModuleActionCollection Implements Entities.Modules.IActionable.ModuleActions
            Get
                Dim Actions As New Entities.Modules.Actions.ModuleActionCollection
                Actions.Add(GetNextActionID, Localization.GetString("EditChurchInfo.Action", LocalResourceFile), Entities.Modules.Actions.ModuleActionType.EditContent, "", "", EditUrl("EditChurchInfo"), False, Security.SecurityAccessLevel.Edit, True, False)
                Return Actions
            End Get
        End Property

        Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.SelectedIndexChanged
            Select Case GridView1.Rows.Item(GridView1.SelectedIndex).Cells.Item(1).Text
                Case Is <> PortalId

                Case Is = PortalId
                    SqlDataSource1.DeleteCommand = "DELETE FROM Congregation WHERE (CongregationID = " & PortalId & ") AND (UserID = " & GridView1.Rows.Item(GridView1.SelectedIndex).Cells.Item(2).Text & ")"
                    SqlDataSource1.Delete()
                    lblDeleteStatus.Text = "PortalID - " & PortalId & " - Removed User ID - " & GridView1.Rows.Item(GridView1.SelectedIndex).Cells.Item(2).Text

            End Select
            DataBind()
        End Sub

        Protected Sub GridView2_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView2.SelectedIndexChanged
            Select Case GridView2.Rows.Item(GridView2.SelectedIndex).Cells.Item(1).Text
                Case Is <> PortalId
                    GridView2.Rows.Item(GridView2.SelectedIndex).Cells.Item(1).Text = PortalId
                    SqlDataSource1.InsertCommand = "INSERT INTO Congregation(CongregationID, UserID ) VALUES (" & PortalId & ", " & GridView2.Rows.Item(GridView2.SelectedIndex).Cells.Item(2).Text & ")"
                    SqlDataSource1.Insert()
                    lblAddStatus.Text = "PortalID - " & PortalId & " - Added User ID - " & GridView2.Rows.Item(GridView2.SelectedIndex).Cells.Item(2).Text & " to Congregation"
                Case Is = PortalId

            End Select
            DataBind()
        End Sub

        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            SQLDataSourceDELETE.SelectCommand = "SELECT Congregation.CongregationID, Users.UserID, Users.DisplayName, Users.FirstName, Users.LastName FROM Users RIGHT OUTER JOIN Congregation ON Users.UserID = Congregation.UserID AND Congregation.CongregationID = " & PortalId & " LEFT OUTER JOIN Roles ON Roles.PortalID = " & PortalId & " AND Roles.RoleName = @CongregationRoleName WHERE  (Users.UserID IS NOT NULL)"
            SqlDataSourceAdd.SelectCommand = "SELECT Congregation.CongregationID, Users.UserID, Users.DisplayName, Users.FirstName, Users.LastName FROM Users LEFT OUTER JOIN Congregation ON Users.UserID = Congregation.UserID LEFT OUTER JOIN Roles ON Roles.PortalID = " & PortalId & "  AND Roles.RoleName = @CongregationRoleName WHERE (Congregation.CongregationID = " & PortalId & " ) OR (Congregation.CongregationID IS NULL)"
        End Sub


        Protected Sub cmdUpdate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdUpdate.Click
            'SqlDataSource2.SelectParameters.
            'SqlDataSource2.SelectParameters.Item("").DefaultValue = ""
        End Sub
    End Class
End Namespace
